package org.huangrui.juc.source.cas;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @Author hr
 * @Create 2024-04-04 16:20
 */
public class T02_AtomicReference {
    public static void main(String[] args) {
        AtomicReference<User> atomicReference = new AtomicReference<>();
        User zs = new User("zs", 22);
        User ls = new User("ls", 29);
        atomicReference.set(zs);

        System.out.println(atomicReference.compareAndSet(zs, ls)+"\t"+atomicReference.get());
        System.out.println(atomicReference.compareAndSet(zs, ls)+"\t"+atomicReference.get());

    }
}
@Getter
@ToString
@AllArgsConstructor
class User{
    String userName;
    int    age;
}